<template>
  <div class="nav">
    <ul class="menu">
      <li v-for="(item, index) in list" :key="index">
        <a href="/">{{ item.title }}</a>
        <ul>
          <li
            v-for="(i, idx) in item.secondTitle"
            :key="idx"
            @click="hanleClick(i.pathName)"
          >
            <a>{{ i.text }}</a>
          </li>
        </ul>
      </li>
    </ul>
  </div>
</template>

<script lang='ts'>
import { reactive, ref, getCurrentInstance } from "vue";

interface obj {
  a: number;
  c: string;
}
export default {
  props: {
    list: {
      type: Array,
      default: [],
    },
  },
  setup(props, context) {
    function hanleClick(pathName) {
      console.log(36,pathName);
      // 待添加报错机制
      context.emit("handleClick", pathName);
    }
    return { hanleClick };
  },
};
</script>

<style lang='scss' scoped>
.nav {
  width: 100%;
  top: 0;
  height: 38px;
  position: absolute;
  left: 0;
  z-index: 1000;
}
.menu {
  position: relative;
  float: left;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  border-radius: 3px;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.5),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.15);
  background: #ccc;
  & > li {
    float: left;
    position: relative;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 1px 0 0 rgba(255, 255, 255, 0.25);
    perspective: 1000px;
    &:first-child {
      border-left: 1px solid rgba(255, 255, 255, 0.25);
      box-shadow: -1px 0 0 rgba(0, 0, 0, 0.1), 1px 0 0 rgba(255, 255, 255, 0.25);
    }
    &:hover {
      & > a {
        background: #333;
        color: rgba(0, 223, 252, 1);
        text-shadow: none;
      }
    }
  }
  a {
    display: block;
    position: relative;
    z-index: 10;
    padding: 13px 20px 13px 20px;
    text-decoration: none;
    color: rgba(75, 75, 75, 1);
    line-height: 1;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: -0.05em;
    background: transparent;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.9);
    transition: all 0.25s ease-in-out;
  }
  li {
    ul {
      position: absolute;
      left: 0;
      z-index: 1;
      width: 200px;
      padding: 0;
      opacity: 0;
      visibility: hidden;
      border-bottom-left-radius: 4px;
      border-bottom-right-radius: 4px;
      background: transparent;
      overflow: hidden;
      transform-origin: 50% 0%;
    }
    &:hover {
      ul {
        padding: 15px 0;
        background: #333;
        opacity: 1;
        visibility: visible;
        box-shadow: 1px 1px 7px rgba(0, 0, 0, 0.5);
        animation-name: swingdown;
        animation-duration: 1s;
        animation-timing-function: ease;
      }
    }
    li {
      a {
        &:hover {
          color: rgba(0, 223, 252, 1);
          border-top: dotted 1px rgba(255, 255, 255, 0.15);
          border-bottom: dotted 1px rgba(255, 255, 255, 0.15);
          background: rgba(0, 223, 252, 0.02);
        }
      }
    }
  }
}
.menu,
.menu ul {
  list-style: none;
}
@keyframes swingdown {
  0% {
    opacity: 0.99999;
    transform: rotateX(90deg);
  }
  30% {
    transform: rotateX(-20deg) rotateY(5deg);
    animation-timing-function: ease-in-out;
  }
  65% {
    transform: rotateX(20deg) rotateY(-3deg);
    animation-timing-function: ease-in-out;
  }
  100% {
    transform: rotateX(0);
    animation-timing-function: ease-in-out;
  }
}
.menu {
  li {
    li {
      a {
        padding-left: 15px;
        font-weight: 400;
        color: #ddd;
        text-shadow: none;
        border-top: dotted 1px transparent;
        border-bottom: dotted 1px transparent;
        transition: all 0.15s linear;
      }
    }
  }
}
</style>